<template>
  <div class="accountLogWrapper">
    <div class="accountLog-top">
      <div class="top">
        <div class="top-item">交易类型</div>
        <div class="top-item-middle">交易记录</div>
        <div class="top-item">账户余额</div>
      </div>
    </div>
    <div class="accountLog-center">
      <scroller height="100%" :pulldown-config="pulldownConfig" :pullup-config="pullupConfig" @pullup:loading="loadMore" @pulldown:loading="refresh" lock-x use-pullup use-pulldown>
        <div class="content">

          <div class="content-item" v-for="item in accountLogList">
            <div class="left">
              <p class="type">{{item.type}}</p>
              <p class="time">{{item.addTime}}</p>
            </div>
            <div class="middle sub" v-if="item.moneyType === 'sub'">-<span>{{item.money}}</span></div>
            <div class="middle add" v-if="item.moneyType === 'add'">+<span>{{item.money}}</span></div>
            <div class="right">{{item.afterMoney}}</div>
          </div>

        </div>
      </scroller>
    </div>


    <!--<div style="height: 4rem;"></div>-->
  </div>
</template>
<script>
  import { Scroller } from './../../components'
  var LocalStorageUtil = require('./../../commons/js/LocalStorageUtil.js')
  var MyRequest = require('./../../commons/js/MyRequest.js')
  var Global = require("./../../commons/js/Global.js")
  export default {
    data () {
      return {
        accountLogList: '',
        userInfo: LocalStorageUtil.getItem("User"),
        begin: 0,
        page: 1,
        pageCount: 10,
        uuid: '',
        loadingType: 0,
        pulldownConfig: {content:'下拉刷新', height: 40, autoRefresh: false, downContent:'下拉刷新',upContent: '释放刷新',loadingContent:'加载中', clsPrefix: 'xs-plugin-pullup-'},
        pullupConfig: {content:'下拉刷新', pullUpHeight: 60, height: 40, autoRefresh: false, downContent:'下拉刷新',upContent: '释放刷新',loadingContent:'加载中', clsPrefix: 'xs-plugin-pullup-'}
      }
    },
    components: {
      Scroller
    },
    created: function () {
      this.loading()
    },
    methods: {
      solveData (data) {
        for(var i = 0; i < data.length; i ++) {
          var item = data[i]
          if(item.beforeMoney > item.afterMoney) {
            item.moneyType = 'sub'
          } else {
            item.moneyType = 'add'
          }
          data[i] = item
        }
        return data
      },
      loading () {
        var data = {
          action: 'list',
          begin: this.begin,
          end: this.page * this.pageCount,
          order: "by addTime desc",
          accountId: this.userInfo.id
        }
        console.log(data)
        MyRequest.MyGetWithToast("AccountLog", this, function (result, that) {
          console.log(result)
          if(result.success) {
            that.accountLogList = that.solveData(result.data)
            that.page ++
          } else {
            Global.showToast("数据加载失败", that)
          }
          if(that.loadingType == 1) {
            that.$broadcast('pulldown:reset', that.uuid)
          } else if( that.loadingType == 2) {
            that.$broadcast('pullup:reset', that.uuid)
          }
          that.loadingType = 0
          Global.closeLoading()
        }, data)
      },
      loadMore (uuid) {
        this.uuid = uuid
        this.loadingType = 2
        this.loading()
      },
      refresh (uuid) {
        this.uuid = uuid
        this.page = 1
        this.loadingType = 1
        this.loading()
      },
    }
  }
</script>
<style lang="less">
  @import './accountLog.less';
</style>
